package com.jiaeda.shiroweb.mapper;

import com.jiaeda.shiroweb.entity.SysRole;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by chengchaopeng on 2018/6/27.
 */
@Mapper
@Component
public interface SysRoleMapper {

    @Select("select role_id as roleId,role_key as roleKey,DATE_FORMAT(create_time, '%Y-%m-%d %T') as createTime," +
            "description " +
            "from sys_role where role_key=#{roleKey}")
    SysRole findByRoleKey(@Param("roleKey") String roleKey);

    @Select("<script>select role_id as roleId,role_key as roleKey,DATE_FORMAT(create_time, '%Y-%m-%d %T') as createTime," +
            "description from sys_role " +
            "WHERE" +
            "<if test=\"roleIds!=null\">" +
            " role_id in " +
            "<foreach collection='roleIds' index='index' item='item' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</if></script>")
    List<SysRole> findByRoleIds(@Param("roleIds") String[] roleIds);


}
